// import { isNull, isNumber, isObject, isString, isArray, isSymbol } from '@/unit/tool';

const columns = [
  // {
  //   title: "",
  //   fixed: "left",
  //   width: "40px",
  //   dataIndex: "leftExt",
  //   ellipsis: false,
  //   scopedSlots: { customRender: "leftExt" }
  // },
  {
    title: '模板名称',
    fixed: 'left',
    width: '180px',
    dataIndex: 'name',
    ellipsis: false,
  },
  // {
  //   title: '添加公司',
  //   fixed: 'left',
  //   width: '180px',
  //   dataIndex: 'companyId',
  //   ellipsis: false,
  // },
  {
    title: '步骤数',
    width: '180px',
    dataIndex: 'rootStepCount',
    ellipsis: false,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: '180px',
    ellipsis: false,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    width: '180px',
    ellipsis: false,
  },
  {
    title: '操作',
    fixed: 'right',
    dataIndex: 'operateBtn',
    width: 'auto',
    ellipsis: false,
    scopedSlots: { customRender: 'operateBtn' },
  },
];

function formatState(state) {
  switch (state) {
    case 1:
      return '发货';
    case 2:
      return '收货';
    default:
      break;
  }
}

function buildTableData(lists) {
  // let { afterSaleService, appointor, evaluation, repairList, suit } = res;
  let newLists = [];
  lists.forEach((item, index) => {
    newLists.push(buildListsData(item, index));
  });
  return newLists;
}

function buildListsData(item, index) {
  let newRes = { key: index };
  for (let key in item) {
    if (Object.hasOwnProperty.call(item, key)) {
      let obj = item[key];
      if (!isNull(obj)) {
        newRes = Object.assign(newRes, resolveParams(obj, key));
      }
    }
  }
  return newRes;
}

function resolveParams(val, key) {
  if (isNumber(val)) {
    return { [key]: val };
  } else if (isString(val)) {
    return { [key]: val };
  } else if (isArray(val)) {
    return { [key]: val };
  } else if (isObject(val)) {
    let { id, ...restVal } = val;
    return { ...restVal };
  }
}

export { columns, buildTableData };
